package org.agony2d.gpu {
	import org.agony2d.core.agony_internal;
	import org.agony2d.debug.Logger;
	import org.agony2d.gpu.core.BranchAA;
	import org.agony2d.gpu.core.NodeAA;
	
	use namespace agony_internal;
	
	/** [ FusionAA ]
	 * 	[★]
	 *  	1.  FusionAA使用addNode，必须先被addNode到更底层FusionAA....
	 *  		(也就是说，在未被addNode之前，FusionAA不可使用addNode方法....!!)
	 */
public class FusionAA extends BranchAA {
	
	[Inline]
	final override agony_internal function attach( parent:NodeAA ) : void {
		var node:NodeAA
		
		if (parent == this) {
			Logger.reportError(this, "attach", "Node can't be added to self...!!")
		}
		if (!parent.m_fullTex) {
			Logger.reportError(this, "attach", "Parent hasn't been added to any GroupAA...!!")
		}
		if (m_parent) {
			if (m_fullTex != parent.m_fullTex) {
				Logger.reportError(this, "attach", "Full Texture alters...!!")
			}
			node = parent.m_parent
			while (node) {
				if (node == this) {
					Logger.reportError(this, "attach", "无法将对象添加为自身的子对象（或孙对象）的子对象...!!")
				}
				node = node.m_parent
			}
			m_parent.removeNode(this)
			m_altered = true
		}
		else {
			m_fullTex = parent.m_fullTex
		}
		m_parent = parent
		m_world = parent.m_world
	}
	
	[Inline]
	final override agony_internal function render( vertexChanged:Boolean ) : void {
		if (m_numNodes > 0 && !m_invisible) {
			this.doExtractNodes(vertexChanged)
		}
	}
	
	override agony_internal function replaceInternalNode( replaced:Object, shell:Object ) : void {
		var index:int
		
		index = m_nodeList.indexOf(replaced)
		m_nodeList[index] = shell
	}
	
}
}